#include "GamePlay.h"

CGamePlay*CGamePlay::_instance;
CGamePlay::CGamePlay(HWND hwnd)
{
	//Constructor
	_isPause=false;
	_gameLoad=false;
	_hwnd=hwnd;
	//Khoi tao doi tuong Map
	_mapManage=NULL;

	_source.left=_source.top=0;
	_source.right=WINDOW_WIDTH;
	_source.bottom=WINDOW_HEIGHT;
}
CGamePlay::~CGamePlay()
{

}
CGamePlay* CGamePlay::SetInstance(HWND hwnd)
{
	if (_instance==NULL)
	{
		_instance=new CGamePlay(hwnd);
	}
	return _instance;
}
bool CGamePlay::Game_Init()
{
	//May bay
	CWeapon::InitResoure();
	_background=_gr->LoadSurface("Images\\Bagkground.jpg",D3DCOLOR_ARGB(255,0,0,0));
	//Khai bao nhan vat chinh
	//Khai bao menu trong game
	//Khoi tao doi tuong quan lys map
	if(_mapManage!=NULL)
		delete _mapManage;
	_mapManage=new CMap(CGameState::_sound,0);
	//Load cac doi tuong am thanh hinh anh

	return true;
}
void CGamePlay::Game_Run(HWND hwnd,DWORD tickPerFame)
{
	//Chay nhac nen
	_gr->BeginRender(hwnd,_background);
	//Ve map
	_mapManage->Draw();
	if(!_isPause)
		Game_Update(tickPerFame);
	else
	{
		//Hien me nu game;
	}
	_gr->EndRender();
}
void CGamePlay::Game_Load(bool isLoad)
{
	_gameLoad=isLoad;
}
void CGamePlay::Game_Update(DWORD tickPerFrame)
{
	_dxInput->Pool_Keyboard();
	if(_dxInput->OnKeyDown(DIK_ESCAPE))
	{
		//Rest Menu gameplay
		_isPause=true;//Dung
		return;
	}
	if (_gameLoad)
	{
		if (_mapManage!=NULL)
		{
			delete _mapManage;
			_mapManage=new CMap(_sound,0);
		}
		//Thao tac voi doi tuong MapManager
		_gameLoad=false;
	}
	//Update Map
	_mapManage->Update(tickPerFrame,_dxInput);
}
void CGamePlay::Game_Reset()
{
	_isPause=false;
	//Reset doi tuong Map
	_mapManage->Reset();
}
void CGamePlay::Game_End()
{

}